The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section.
The Extensible Markup Language (XML) is a standard for data and documents that has wide acceptance in the computer industry. Relational and object-relational database systems are configured to store and support query mechanisms for XML data. It is important for such database systems to be able to execute SQL queries that embed XML query languages, such as XQuery.
XQuery and SQL share many common concepts and constructs. This facilitates rewriting XQuery constructs in a query into SQL constructs. Queries rewritten in this way can be executed more efficiently.
However, data typing between SQL and XQuery is not identical. SQL relies on static data typing during query compilation because SQL is based on well-typed structured data whose data type is known during query compilation time. XQuery relies on dynamic typing during run time because XQuery deals with semi or unstructured data whose data type is not known during query compilation time. To illustrate, in SQL, a user issues the following query:
select sum(x) from tab
During query compilation time in a database system, a SQL/XML compiler determines the data type of x based on database metadata defining the column data type of x, and then determines the proper SQL summation operator for the data type. During runtime, the summation operator for that specific data type is invoked and executed to compute the sum.
Likewise, for the following issued XQuery query,
sum(fn:doc(“tab”)/x)
during compile time the data type of element x may be determinable if there is an XML schema available. In this case, the XML schema could, for example, define element x as a simple integer data type, then compiling the XQuery sum( ) operator can use SQL sum( ) operator for the integer type.
However, if the XML schema is NOT available, then the data type can only be determined dynamically, i.e. that is during run time, when the actual data is being accessed. Sometimes, even if the XML schema is available, however, the schema states that the element x can be anyType. In this case, the data type of element x is not known until run time. Therefore, the SQL sum( ) operator cannot be used when compiling the XQuery sum( ) operator over such dynamically typed XML data.